Initialization of libraries.
import pandas as pd
import numpy as np
from os import listdir
from os.path import join
import json
from scipy.stats import gaussian_kde
# Visualization libraries
import folium
from folium import plugins
from folium.plugins import HeatMap
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import seaborn as sns
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
from wordcloud import WordCloud, STOPWORDS
from PIL import Image
import urllib
import requests
import chart_studio
import chart_studio.plotly as py
import plotly.offline as pyo
# Set notebook mode to work in offline
pyo.init_notebook_mode()
chart_studio.tools.set_credentials_file(username='arnau.gp',
api_key='YYQ76H4gviCx9st7FhXS')
People in cities live in a constant rush. Hyperconnection through social networks barely let them move the eyes out of the smartphone screen and observe the surroundings. Urban trees are a silent part of the cities' landscape. However, they are certainly unknown for us, but hopefully Data Visualization is going to help us discover some insights, such as:
What is your dataset? Why did you choose this/these particular dataset(s)? What was your goal for the end user's experience?
Datasets
Election of datasets
The purpose of this section is to explore and unveil some insights related to the green elements of Barcelona.
After exploring the data availabe in the Open Data Barcelona portal (https://opendata-ajuntament.barcelona.cat/), the Barcelona's city hall open data portal, 3 datasets were selected. The first dataset contains the gardens and parks, and the last two the trees registered.
So, these datasets were found to be the most relevant to describe Barcelona green elements.
End user experience
The graphic elements created using the afforementioned datasets have been created following one priority: user interactivity. The user should be capable to explore deeper those elements that might be more interesting for itself.
The basic stats are divided into two sections: Gardens and parks, and Trees.
The dataset has only been used for one plot, therefore the only change has been to fill NaN values with a known identifier. This way, data can be filtered easily if necessary.
The dataset is composed by 384 rows and 30 columns.
f = "environment/C006_Parcs_i_jardins.csv"
df_gardens = pd.read_csv(f)
df_gardens.fillna('NO_DATA', inplace=True)
print("Dataset columns: ")
print(df_gardens.columns)
print("\n Total rows: " +str(df_gardens.shape[0]))
print("\n Total rows: " +str(df_gardens.shape[1]))
df_gardens.head()
The dataframe df_arbrat has been used throughout all the plots, therefore the data cleaning and preprocessing has been done in two steps:
df_arbrat processing: The main dataframe cleaning includes:
ad_hoc processing for each plot. For each plot, new dataframes have been created and ad_hoc cleaning and processing has been performed. Some of the most common steps include:
Some of the relevant features of this dataset are:
The dataset basic stats are summarized in the following points:
Given the size of the dataset, some plots and analysis have been conducted only for the top 6 tree species, which represent approximately the 60% of the trees.
Some simple insights that can be found from this first exploration are:
Besides, following, several plots show the basic stats of the dataset in a visual way.
f = "environment/Arbrat_2019.csv"
df_arbrat = pd.read_csv(f)
# Convert dates to datetime
df_arbrat['DATA_PLANTACIO'] = pd.to_datetime(df_arbrat['DATA_PLANTACIO'], format='%d/%m/%Y', errors='coerce')
df_arbrat['ANY_PLANTACIO'] = pd.DatetimeIndex(df_arbrat['DATA_PLANTACIO']).year
df_arbrat['MES_PLANTACIO'] = pd.DatetimeIndex(df_arbrat['DATA_PLANTACIO']).month
df_arbrat['ANY_MES_PLANTACIO'] = df_arbrat['DATA_PLANTACIO'].dt.strftime('%Y-%m')
# Fill NaN values
df_arbrat.fillna('NO_DATA', inplace=True)
df_arbrat.replace({'NaT': 'NO_DATA'}, inplace=True)
# Replace column values using dict
irrigation_type_dict = {"ALTRES": "Other",
"ASPERSIÓ": "Sprinkling",
"DIFUSIÓ": "Diffusion",
"GOTEIG": "Drip",
"MÀNEGA": "Hose",
"ROTATOR": "Rotary"
}
element_type_dict = {"ARBRE ZONA": "Zone tree",
"ARBRE VIARI": "Road tree",
"PALMERA ZONA": "Zone palm",
"PALMERA VIARI": "Road palm",
}
tree_pit_size_dict = {"ALTRES": "Other",
"ENTRE 60 I 100 cm": "60 cm < Size < 100 cm",
"major que o igual a 100 cm": "Size >= 100 cm",
"menor que o igual a 60 cm": "Size <= 60 cm",
}
tree_pit_edge_dict = {"ALTRES": "Other",
"SENSE VORA": "No edge",
"VORA FORMIGÓ": "Concrete edge",
"VORA METÀL·LICA": "Metallic edge",
}
tree_pit_cover_dict = {"SENSE COBERTURA": "No cover",
"ALTRES": "Other",
"ENCOIXINAT": "Cushioned",
"GRAVA": "Gravel",
"LLAMBORDA": "Cobblestone",
"PAVIMENT DRENAT": "Drained pavement",
"REIXETA FORMIGÓ": "Concrete mesh strainer",
"REIXETA METÀL·LICA": "Metallic mesh strainer"
}
tree_pit_support_dict = {"ALTRES": "Other",
"ESCOCELL ELEVAT": "Elevated tree pit",
"ESCOCELL QUADRAT": "Squared tree pit",
"ESCOCELL RECTANGULAR": "Rectangular tree pit",
"ESCOCELL RODÓ": "Circular tree pit",
"ESCOCELL TRIANGULAR": "Triangular tree pit",
"JARDINERA": "Planter",
"PARTERRE": "Flower bed",
"PARTERRE ELEVAT": "Elevated flower bed"
}
tree_pit_surface_dict = {"ALTRES": "Other",
"GESPA": "Grass",
"GESPA AMB VEGETACIÓ": "Grass with vegetation",
"PAVIMENT": "Pavement",
"SAULÓ AMB VEGETACIÓ": "Sandstone with vegetation",
"SAULÓ SENSE VEGETACIÓ": "Sandstone without vegetation"
}
df_arbrat.replace({"TIPUS_REG": irrigation_type_dict,
"TIPUS_ELEMENT": element_type_dict,
"MIDA_ESCOCELL": tree_pit_size_dict,
"VORA_ESCOCELL": tree_pit_edge_dict,
"COBERTURA_ESCOCELL": tree_pit_cover_dict,
"TIPUS_SUPORT": tree_pit_support_dict,
"TIPUS_SUPERFICIE": tree_pit_surface_dict,
}, inplace=True)
print("Dataset columns: ")
print(df_arbrat.columns)
print("\n Total rows: " +str(df_arbrat.shape[0]))
print("\n Total rows: " +str(df_arbrat.shape[1]))
print("\n Dataset info: ")
print(df_arbrat.info())
df_arbrat.head()
df_arbrat_names = df_arbrat.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_names = df_arbrat_names.sort_values(['CODI'], ascending=False)
total_trees = df_arbrat.shape[0]
total_type_trees = len(df_arbrat['NOM_CIENTIFIC'].unique())
bcn_square_kms = 101.3
bcn_population_2019 = 1636762
tree_o2_kg_year = 100
person_o2_kg_year = 740
trees_square_km = int(total_trees/bcn_square_kms)
trees_per_inhabitant = float(total_trees/bcn_population_2019)
delta_o2_year = ((tree_o2_kg_year*total_trees)-(person_o2_kg_year*bcn_population_2019))/1000000
print("Total urban trees: " + str(total_trees))
print("Total types of tree: " + str(total_type_trees))
print("Trees/square km: " + str(trees_square_km))
print("Trees per inhabitant: " + str(trees_per_inhabitant))
print("Delta O2 year: " + str(delta_o2_year) + " millions")
fig = go.Figure(go.Bar(
x=df_arbrat_names['CODI'][:10][::-1],
y=df_arbrat_names['NOM_CIENTIFIC'][:10][::-1],
orientation='h'))
top_6_total_trees = df_arbrat_names['CODI'][:10].sum()
print("Top 6 types of tree: " + str(top_6_total_trees))
print("Top 6 types of tree % over all: " + str(top_6_total_trees/total_trees))
# Set titles
fig.update_layout(
title="Count of trees by tree specie",
yaxis_title="Tree specie",
xaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
df_arbrat_type = df_arbrat.copy(deep=True)
df_arbrat_type = df_arbrat_type.groupby(['TIPUS_ELEMENT'], as_index=False).count()
fig = go.Figure([go.Bar(x=df_arbrat_type['TIPUS_ELEMENT'], y=df_arbrat_type['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree zone",
xaxis_title="Tree zone",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
Only roughly the 10% of the total trees have registered the irrigation type.
df_arbrat_reg = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_irrigation = (len(df_arbrat_reg[df_arbrat_reg['TIPUS_REG']=='NO_DATA'])+
len(df_arbrat_reg[df_arbrat_reg['TIPUS_REG']=='SENSE INFORMAR']))
df_arbrat_reg = df_arbrat_reg[df_arbrat_reg['TIPUS_REG']!='NO_DATA']
df_arbrat_reg = df_arbrat_reg[df_arbrat_reg['TIPUS_REG']!='SENSE INFORMAR']
df_arbrat_reg = df_arbrat_reg.groupby(['TIPUS_REG'], as_index=False).count()
print("Number of trees without irrigation type known: " + str(unknown_irrigation))
print("Percentage of trees without irrigation type known: " + str(unknown_irrigation/total_trees*100))
fig = go.Figure([go.Bar(x=df_arbrat_reg['TIPUS_REG'], y=df_arbrat_reg['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree irrigation type",
xaxis_title="Tree irrigation type",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
# py.plot(fig, filename='test')
df_arbrat_escocell = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_escocell = len(df_arbrat_escocell[df_arbrat_escocell['MIDA_ESCOCELL']=='NO_DATA'])
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['MIDA_ESCOCELL']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell.groupby(['MIDA_ESCOCELL'], as_index=False).count()
print("Number of trees without tree pit size known: " + str(unknown_escocell))
print("Percentage of trees without tree pit size known: " + str(unknown_escocell/total_trees*100))
fig = go.Figure([go.Bar(x=df_arbrat_escocell['MIDA_ESCOCELL'], y=df_arbrat_escocell['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree pit size",
xaxis_title="Tree pit size",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
df_arbrat_escocell = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_escocell = len(df_arbrat_escocell[df_arbrat_escocell['VORA_ESCOCELL']=='NO_DATA'])
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['VORA_ESCOCELL']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell.groupby(['VORA_ESCOCELL'], as_index=False).count()
print("Number of trees without tree pit edge known: " + str(unknown_escocell))
print("Percentage of trees without tree pit edge known: " + str(unknown_escocell/total_trees*100))
fig = go.Figure([go.Bar(x=df_arbrat_escocell['VORA_ESCOCELL'], y=df_arbrat_escocell['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree pit edge",
xaxis_title="Tree pit edge",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
df_arbrat_escocell = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_escocell = len(df_arbrat_escocell[df_arbrat_escocell['COBERTURA_ESCOCELL']=='NO_DATA'])
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['COBERTURA_ESCOCELL']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell.groupby(['COBERTURA_ESCOCELL'], as_index=False).count()
print("Number of trees without tree pit cover known: " + str(unknown_escocell))
print("Percentage of trees without tree pit cover known: " + str(unknown_escocell/total_trees*100))
fig = go.Figure([go.Bar(x=df_arbrat_escocell['COBERTURA_ESCOCELL'], y=df_arbrat_escocell['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree pit cover",
xaxis_title="Tree pit cover",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
df_arbrat_escocell = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_escocell = len(df_arbrat_escocell[df_arbrat_escocell['TIPUS_SUPERFICIE']=='NO_DATA'])
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['TIPUS_SUPERFICIE']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell.groupby(['TIPUS_SUPERFICIE'], as_index=False).count()
print("Number of trees without tree pit surface known: " + str(unknown_escocell))
print("Percentage of trees without tree pit surface known: " + str(unknown_escocell/total_trees*100))
fig = go.Figure([go.Bar(x=df_arbrat_escocell['TIPUS_SUPERFICIE'], y=df_arbrat_escocell['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree pit surface",
xaxis_title="Tree pit surface",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
df_arbrat_escocell = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_escocell = len(df_arbrat_escocell[df_arbrat_escocell['TIPUS_SUPORT']=='NO_DATA'])
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['TIPUS_SUPORT']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell.groupby(['TIPUS_SUPORT'], as_index=False).count()
print("Number of trees without tree pit support known: " + str(unknown_escocell))
print("Percentage of trees without tree pit support known: " + str(unknown_escocell/total_trees*100))
fig = go.Figure([go.Bar(x=df_arbrat_escocell['TIPUS_SUPORT'], y=df_arbrat_escocell['CODI'])])
# Set titles
fig.update_layout(
title="Count of trees by tree pit support",
xaxis_title="Tree pit support",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=500,
)
fig.show()
df_arbrat_escocell = df_arbrat.copy(deep=True)
total_trees = df_arbrat.shape[0]
unknown_escocell = df_arbrat_escocell[df_arbrat_escocell['AMPLADA_VORERA']=='NO_DATA']
unknown_escocell = len(df_arbrat_escocell[df_arbrat_escocell['MIDA_ESCOCELL']=='NO_DATA'])
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['AMPLADA_VORERA']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['AMPLADA_VORERA']!=-1.0]
df_arbrat_escocell = df_arbrat_escocell[df_arbrat_escocell['MIDA_ESCOCELL']!='NO_DATA']
df_arbrat_escocell = df_arbrat_escocell.groupby(['MIDA_ESCOCELL','AMPLADA_VORERA'], as_index=False).count()
print("Number of trees without sidewalk width known: " + str(unknown_escocell))
print("Percentage of trees without irrigation type known: " + str((unknown_escocell)/total_trees*100))
fig = go.Figure()
for size in df_arbrat_escocell['MIDA_ESCOCELL'].unique():
fig.add_trace(go.Scatter(x=df_arbrat_escocell[df_arbrat_escocell['MIDA_ESCOCELL']==size]['AMPLADA_VORERA'],
y=df_arbrat_escocell[df_arbrat_escocell['MIDA_ESCOCELL']==size]['CODI'],
name=str(size),
mode='markers'
))
# Add range slider
fig.update_layout(
xaxis=dict(
rangeslider=dict(
visible=True
),
type="linear"
)
)
# Set titles
fig.update_layout(
title="Count of trees by sidewalk and tree pit width",
xaxis_title="Sidewalk width",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
)
fig.show()
The focus of the data analysis has pivoted in two points: tree specie and irrigation type. This two columns have then been related with the rest of data to show different patterns. The main findings have been:
The genre of this project part is Annotated Graph/Map.
The tools used from Visual Narrative (Figure 7 in Segal and Heer) are:
The tools used from Narrative Structure (Figure 7 in Segal and Heer) are:
The chosen visualization have been:
Almost all the graphs are interactive since the purpose is to keep user interactivity at its most.
weights = list()
weights_dict = dict()
font_path = "/Users/arnaugatell/Desktop/DTU/Social_Data_Analysis_and_Visualization/Assignments/Project/font_m__1m/mplus-1m-regular.ttf"
for index, row in df_arbrat_names.iterrows():
weights.append((row['NOM_CIENTIFIC'], row['CODI']))
for k,v in weights:
weights_dict[k] = int(v)
image_mask = np.array(Image.open("arbol.png"))
stopwords = set(STOPWORDS)
wc = WordCloud(height=1000, width=1000, background_color="white", max_words=2000, mask=image_mask,
stopwords=STOPWORDS, contour_width=1, font_path=font_path)
# generate word cloud
wc.generate_from_frequencies(weights_dict)
# store to file
wc.to_file("trees_wc.png")
# show
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.figure(figsize=(20,20))
plt.show()
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['ANY_PLANTACIO']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['ANY_MES_PLANTACIO']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='SENSE INFORMAR']
# Three df grouped by
df_arbrat_year = df_arbrat_interactive.groupby(['ANY_PLANTACIO','TIPUS_REG'], as_index=False).count()
df_arbrat_year_month = df_arbrat_interactive.groupby(['ANY_MES_PLANTACIO','TIPUS_REG'], as_index=False).count()
# Initialize figure
fig = go.Figure()
irrigation_types = list()
# Add Traces
for irrigation_type in df_arbrat_interactive['TIPUS_REG'].unique():
irrigation_types.append(str(irrigation_type))
fig.add_trace(
go.Bar(x=df_arbrat_year[df_arbrat_year['TIPUS_REG']==irrigation_type]['ANY_PLANTACIO'],
y=df_arbrat_year[df_arbrat_year['TIPUS_REG']==irrigation_type]['CODI'],
name=irrigation_type))
fig.add_trace(
go.Bar(x=df_arbrat_year_month[df_arbrat_year_month['TIPUS_REG']==irrigation_type]['ANY_MES_PLANTACIO'],
y=df_arbrat_year_month[df_arbrat_year_month['TIPUS_REG']==irrigation_type]['CODI'],
visible=False,
name=irrigation_type))
# Add drowdowns
button_layer_1_height = 1.185
fig.update_layout(
updatemenus=[
dict(
buttons=list([
dict(label="All by Year",
method="update",
args=[{"visible": [True, False, True, False, True, False,
True, False, True, False, True, False,
True, False, True, False, True, False
]},
{"title": "Type of irrigation devices"}]),
dict(label="All by Year-Month",
method="update",
args=[{"visible": [False, True, False, True, False, True,
False, True, False, True, False, True,
False, True, False, True, False, True
]},
{"title": "Type of irrigation devices"}]),
]),
type="buttons",
direction="right",
active=0,
x=1.0,
y=1.15,
),
dict(
buttons=list([
dict(label="All by Year",
method="update",
args=[{"visible": [True, False, True, False, True, False,
True, False, True, False, True, False,
True, False, True, False, True, False
]},
{"title": "Type of irrigation devices"}]),
dict(label=str(irrigation_types[0]),
method="update",
args=[{"visible": [True] + 11*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[0]) + " by Year"}]),
dict(label=str(irrigation_types[1]),
method="update",
args=[{"visible": 2*[False] + [True] + 9*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[1]) + " by Year"}]),
dict(label=str(irrigation_types[2]),
method="update",
args=[{"visible": 4*[False] + [True] + 7*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[2]) + " by Year"}]),
dict(label=str(irrigation_types[3]),
method="update",
args=[{"visible": 6*[False] + [True] + 5*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[3]) + " by Year"}]),
dict(label=str(irrigation_types[4]),
method="update",
args=[{"visible": 8*[False] + [True] + 3*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[4]) + " by Year"}]),
dict(label=str(irrigation_types[5]),
method="update",
args=[{"visible": 10*[False] + [True] + [False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[5]) + " by Year"}]),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.36,
xanchor="left",
y=button_layer_1_height,
yanchor="top"
),
dict(
buttons=list([
dict(label="All by Year-Month",
method="update",
args=[{"visible": [False, True, False, True, False, True,
False, True, False, True, False, True,
False, True, False, True, False, True
]},
{"title": "Type of irrigation devices"}]),
dict(label=str(irrigation_types[0]),
method="update",
args=[{"visible": [False] + [True] + 10*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[0]) + " by Year-month"}]),
dict(label=str(irrigation_types[1]),
method="update",
args=[{"visible": 3*[False] + [True] + 8*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[1]) + " by Year-month"}]),
dict(label=str(irrigation_types[2]),
method="update",
args=[{"visible": 5*[False] + [True] + 6*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[2]) + " by Year-month"}]),
dict(label=str(irrigation_types[3]),
method="update",
args=[{"visible": 7*[False] + [True] + 4*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[3]) + " by Year-month"}]),
dict(label=str(irrigation_types[4]),
method="update",
args=[{"visible": 9*[False] + [True] + 2*[False]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[4]) + " by Year-month"}]),
dict(label=str(irrigation_types[5]),
method="update",
args=[{"visible": 11*[False] + [True]},
{"title": "Type of irrigation device:<br>" + str(irrigation_types[5]) + " by Year-month"}]),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.5,
xanchor="left",
y=button_layer_1_height,
yanchor="top"
),
]
)
fig.update_layout(
annotations=[
dict(text="Year", x=0.38, xref="paper", y=1.23, yref="paper",
align="left", showarrow=False),
dict(text="Year-Month", x=0.545, xref="paper", y=1.23, yref="paper",
showarrow=False)
])
# Add range slider
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=5,
label="last 5y",
step="year",
stepmode="backward"),
dict(count=10,
label="last 10y",
step="year",
stepmode="backward"),
dict(step="all")
]),
x=0.8,
y=1.21
),
rangeslider=dict(
visible=True
),
type="date"
)
)
# Set titles
fig.update_layout(
title="Type of irrigation devices",
xaxis_title="Date of planting",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
)
fig.update_layout(legend=dict(x=0, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='type-of-irrigation-planting-date')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['MIDA_ESCOCELL']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']!='NO_DATA']
df_arbrat_type_count = df_arbrat_interactive.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_type_count = df_arbrat_type_count.sort_values(['CODI'], ascending=False)
# Three df grouped by
df_arbrat_mida = df_arbrat_interactive.groupby(['MIDA_ESCOCELL','NOM_CIENTIFIC'], as_index=False).count()
# Initialize figure
fig = go.Figure()
top_n = 6
tree_types = list()
# Add Traces
for tree_type in df_arbrat_type_count['NOM_CIENTIFIC'].unique()[:top_n]:
tree_types.append(str(tree_type))
fig.add_trace(
go.Bar(x=df_arbrat_mida[df_arbrat_mida['NOM_CIENTIFIC']==tree_type]['MIDA_ESCOCELL'],
y=df_arbrat_mida[df_arbrat_mida['NOM_CIENTIFIC']==tree_type]['CODI'],
name=tree_type))
# Set titles
fig.update_layout(
title="Tree pit size by tree specie",
xaxis_title="Tree pit size",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
# barmode='stack',
xaxis={'categoryorder':'total descending'})
fig.update_layout(legend=dict(x=0.7, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='tree_pit_size-tree_specie')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['VORA_ESCOCELL']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']!='NO_DATA']
df_arbrat_type_count = df_arbrat_interactive.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_type_count = df_arbrat_type_count.sort_values(['CODI'], ascending=False)
# Three df grouped by
df_arbrat_mida = df_arbrat_interactive.groupby(['VORA_ESCOCELL','NOM_CIENTIFIC'], as_index=False).count()
# Initialize figure
fig = go.Figure()
top_n = 6
tree_types = list()
# Add Traces
for tree_type in df_arbrat_type_count['NOM_CIENTIFIC'].unique()[:top_n]:
tree_types.append(str(tree_type))
fig.add_trace(
go.Bar(x=df_arbrat_mida[df_arbrat_mida['NOM_CIENTIFIC']==tree_type]['VORA_ESCOCELL'],
y=df_arbrat_mida[df_arbrat_mida['NOM_CIENTIFIC']==tree_type]['CODI'],
name=tree_type))
# Set titles
fig.update_layout(
title="Tree pit edge by tree specie",
xaxis_title="Tree pit edge",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
# barmode='stack',
xaxis={'categoryorder':'total descending'})
fig.update_layout(legend=dict(x=0.7, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='tree-pit-edge-tree-specie')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_SUPERFICIE']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='SENSE INFORMAR']
# Three df grouped by
df_arbrat_superf = df_arbrat_interactive.groupby(['TIPUS_SUPERFICIE','TIPUS_REG'], as_index=False).count()
# Initialize figure
fig = go.Figure()
x_superf = df_arbrat_interactive['TIPUS_SUPERFICIE'].unique()
irrigation_types = df_arbrat_interactive['TIPUS_REG'].unique()
# Add Traces
for surface in x_superf:
fig.add_trace(
go.Bar(name=surface,
y=df_arbrat_superf[df_arbrat_superf['TIPUS_SUPERFICIE']==surface]['CODI'],
x=df_arbrat_superf[df_arbrat_superf['TIPUS_SUPERFICIE']==surface]['TIPUS_REG']))
# Set titles
fig.update_layout(
title="Type of irrigation devices by tree pit surface",
xaxis_title="Irrigation type",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
# barmode='stack',
xaxis={'categoryorder':'total descending'})
fig.update_layout(legend=dict(x=0.7, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='irrigation-tree_pit_surface')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_SUPORT']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='SENSE INFORMAR']
# Three df grouped by
df_arbrat_suport = df_arbrat_interactive.groupby(['TIPUS_SUPORT','TIPUS_REG'], as_index=False).count()
# Initialize figure
fig = go.Figure()
x_suport = df_arbrat_interactive['TIPUS_SUPORT'].unique()
irrigation_types = df_arbrat_interactive['TIPUS_REG'].unique()
# Add Traces
for support in x_suport:
fig.add_trace(
go.Bar(name=support,
y=df_arbrat_suport[df_arbrat_suport['TIPUS_SUPORT']==support]['CODI'],
x=df_arbrat_suport[df_arbrat_suport['TIPUS_SUPORT']==support]['TIPUS_REG']))
# Set titles
fig.update_layout(
title="Type of irrigation devices by tree pit support",
xaxis_title="Irrigation type",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
# barmode='stack',
xaxis={'categoryorder':'total descending'})
fig.update_layout(legend=dict(x=0.8, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='irrigation-tree_pit_support')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_SUPERFICIE']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='SENSE INFORMAR']
# Three df grouped by
df_arbrat_superf = df_arbrat_interactive.groupby(['TIPUS_SUPERFICIE','TIPUS_REG'], as_index=False).count()
fig = go.Figure()
x_superf = df_arbrat_interactive['TIPUS_SUPERFICIE'].unique()
irrigation_types = df_arbrat_interactive['TIPUS_REG'].unique()
# Add Traces
for surface in x_superf:
fig.add_trace(
go.Scatterpolar(
r=df_arbrat_superf[df_arbrat_superf['TIPUS_SUPERFICIE']==surface]['CODI'],
theta=df_arbrat_superf[df_arbrat_superf['TIPUS_SUPERFICIE']==surface]['TIPUS_REG'],
fill='toself',
name=surface
)
)
# Add Buttons
fig.update_layout(
updatemenus=[
dict(
dict(
active=0,
x=1.0,
y=1.15,
buttons=
list([
dict(label="All",
method="update",
args=[{"visible": [True, True, True, True, True, True]},
{"title": "Type of irrigation devices by tree pit surface"}]),
dict(label=x_superf[0],
method="update",
args=[{"visible": [True, False, False, False, False, False]},
{"title": irrigation_types[0]}]),
dict(label=x_superf[1],
method="update",
args=[{"visible": [False, True, False, False, False, False]},
{"title": irrigation_types[1]}]),
dict(label=x_superf[2],
method="update",
args=[{"visible": [False, False, True, False, False, False]},
{"title": irrigation_types[2]}]),
dict(label=x_superf[3],
method="update",
args=[{"visible": [False, False, False, True, False, False]},
{"title": irrigation_types[3]}]),
dict(label=x_superf[4],
method="update",
args=[{"visible": [False, False, False, False, True, False]},
{"title": irrigation_types[4]}]),
dict(label=x_superf[5],
method="update",
args=[{"visible": [False, False, False, False, False, True]},
{"title": irrigation_types[5]}])
]),
)
)
])
fig.update_layout(
title="Type of irrigation devices by tree pit surface",
polar=dict(
radialaxis=dict(
visible=True,
)),
showlegend=False
)
fig.show()
py.plot(fig, filename='radar-irrigation-tree_pit_surface')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_SUPORT']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['TIPUS_REG']!='SENSE INFORMAR']
# Three df grouped by
df_arbrat_suport = df_arbrat_interactive.groupby(['TIPUS_SUPORT','TIPUS_REG'], as_index=False).count()
fig = go.Figure()
x_support = df_arbrat_interactive['TIPUS_SUPORT'].unique()
irrigation_types = df_arbrat_interactive['TIPUS_REG'].unique()
# Add Traces
for support in x_support:
fig.add_trace(
go.Scatterpolar(
r=df_arbrat_suport[df_arbrat_suport['TIPUS_SUPORT']==support]['CODI'],
theta=df_arbrat_suport[df_arbrat_suport['TIPUS_SUPORT']==support]['TIPUS_REG'],
fill='toself',
name=support
)
)
# Add Buttons
fig.update_layout(
updatemenus=[
dict(
dict(
active=0,
x=1.0,
y=1.15,
buttons=
list([
dict(label="All",
method="update",
args=[{"visible": [True, True, True, True, True, True, True, True, True]},
{"title": "Type of irrigation devices by tree pit support"}]),
dict(label=x_support[0],
method="update",
args=[{"visible": [True, False, False, False, False, False, False, False, False]},
{"title": irrigation_types[0]}]),
dict(label=x_support[1],
method="update",
args=[{"visible": [False, True, False, False, False, False, False, False, False]},
{"title": irrigation_types[1]}]),
dict(label=x_support[2],
method="update",
args=[{"visible": [False, False, True, False, False, False, False, False, False]},
{"title": irrigation_types[2]}]),
dict(label=x_support[3],
method="update",
args=[{"visible": [False, False, False, True, False, False, False, False, False]},
{"title": irrigation_types[3]}]),
dict(label=x_support[4],
method="update",
args=[{"visible": [False, False, False, False, True, False, False, False, False]},
{"title": irrigation_types[4]}]),
dict(label=x_support[5],
method="update",
args=[{"visible": [False, False, False, False, False, True, False, False, False]},
{"title": irrigation_types[5]}]),
dict(label=x_support[6],
method="update",
args=[{"visible": [False, False, False, False, False, False, True, False, False]},
{"title": irrigation_types[5]}]),
dict(label=x_support[7],
method="update",
args=[{"visible": [False, False, False, False, False, False, False, True, False]},
{"title": irrigation_types[5]}]),
dict(label=x_support[8],
method="update",
args=[{"visible": [False, False, False, False, False, False, False, False, True]},
{"title": irrigation_types[5]}])
]),
)
)
])
fig.update_layout(
title="Type of irrigation devices by tree pit support",
polar=dict(
radialaxis=dict(
visible=True,
)),
showlegend=False
)
fig.show()
py.plot(fig, filename='radar-irrigation-tree_pit_support')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['ANY_PLANTACIO']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['ANY_MES_PLANTACIO']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']!='NO_DATA']
df_arbrat_type_count = df_arbrat_interactive.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_type_count = df_arbrat_type_count.sort_values(['CODI'], ascending=False)
# Three df grouped by
df_arbrat_year = df_arbrat_interactive.groupby(['ANY_PLANTACIO','NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_year_month = df_arbrat_interactive.groupby(['ANY_MES_PLANTACIO','NOM_CIENTIFIC'], as_index=False).count()
# Initialize figure
fig = go.Figure()
top_n = 6
tree_types = list()
# Add Traces
for tree_type in df_arbrat_type_count['NOM_CIENTIFIC'].unique()[:top_n]:
tree_types.append(str(tree_type))
fig.add_trace(
go.Bar(x=df_arbrat_year[df_arbrat_year['NOM_CIENTIFIC']==tree_type]['ANY_PLANTACIO'],
y=df_arbrat_year[df_arbrat_year['NOM_CIENTIFIC']==tree_type]['CODI'],
name=tree_type))
fig.add_trace(
go.Bar(x=df_arbrat_year_month[df_arbrat_year_month['NOM_CIENTIFIC']==tree_type]['ANY_MES_PLANTACIO'],
y=df_arbrat_year_month[df_arbrat_year_month['NOM_CIENTIFIC']==tree_type]['CODI'],
visible=False,
name=tree_type))
# Add drowdowns
fig.update_layout(
updatemenus=[
dict(
buttons=list([
dict(label="All by Year",
method="update",
args=[{"visible": [True, False, True, False, True, False,
True, False, True, False, True, False,
True, False, True, False, True, False
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
dict(label="All by Year-Month",
method="update",
args=[{"visible": [False, True, False, True, False, True,
False, True, False, True, False, True,
False, True, False, True, False, True
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
]),
type="buttons",
direction="right",
active=0,
x=1.0,
y=1.15,
),
dict(
buttons=list([
dict(label="All by Year",
method="update",
args=[{"visible": [True, False, True, False, True, False,
True, False, True, False, True, False,
True, False, True, False, True, False
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
dict(label=str(tree_types[0]),
method="update",
args=[{"visible": [True] + 11*[False]},
{"title": "Type of tree:<br>" + str(tree_types[0]) + " by Year"}]),
dict(label=str(tree_types[1]),
method="update",
args=[{"visible": 2*[False] + [True] + 9*[False]},
{"title": "Type of tree:<br>" + str(tree_types[1]) + " by Year"}]),
dict(label=str(tree_types[2]),
method="update",
args=[{"visible": 4*[False] + [True] + 7*[False]},
{"title": "Type of tree:<br>" + str(tree_types[2]) + " by Year"}]),
dict(label=str(tree_types[3]),
method="update",
args=[{"visible": 6*[False] + [True] + 5*[False]},
{"title": "Type of tree:<br>" + str(tree_types[3]) + " by Year"}]),
dict(label=str(tree_types[4]),
method="update",
args=[{"visible": 8*[False] + [True] + 3*[False]},
{"title": "Type of tree:<br>" + str(tree_types[4]) + " by Year"}]),
dict(label=str(tree_types[5]),
method="update",
args=[{"visible": 10*[False] + [True] + [False]},
{"title": "Type of tree:<br>" + str(tree_types[5]) + " by Year"}]),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.38,
xanchor="left",
y=1.33,
yanchor="top"
),
dict(
buttons=list([
dict(label="All by Year-Month",
method="update",
args=[{"visible": [False, True, False, True, False, True,
False, True, False, True, False, True,
False, True, False, True, False, True
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
dict(label=str(tree_types[0]),
method="update",
args=[{"visible": [False] + [True] + 10*[False]},
{"title": "Type of tree:<br>" + str(tree_types[0]) + " by Year-month"}]),
dict(label=str(tree_types[1]),
method="update",
args=[{"visible": 3*[False] + [True] + 8*[False]},
{"title": "Type of tree:<br>" + str(tree_types[1]) + " by Year-month"}]),
dict(label=str(tree_types[2]),
method="update",
args=[{"visible": 5*[False] + [True] + 6*[False]},
{"title": "Type of tree:<br>" + str(tree_types[2]) + " by Year-month"}]),
dict(label=str(tree_types[3]),
method="update",
args=[{"visible": 7*[False] + [True] + 4*[False]},
{"title": "Type of tree:<br>" + str(tree_types[3]) + " by Year-month"}]),
dict(label=str(tree_types[4]),
method="update",
args=[{"visible": 9*[False] + [True] + 2*[False]},
{"title": "Type of tree:<br>" + str(tree_types[4]) + " by Year-month"}]),
dict(label=str(tree_types[5]),
method="update",
args=[{"visible": 11*[False] + [True]},
{"title": "Type of tree:<br>" + str(tree_types[5]) + " by Year-month"}]),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.38,
xanchor="left",
y=1.185,
yanchor="top"
),
]
)
fig.update_layout(
annotations=[
dict(text="Year", x=0.345, xref="paper", y=1.275, yref="paper",
align="left", showarrow=False),
dict(text="Year-Month", x=0.275, xref="paper", y=1.13, yref="paper",
showarrow=False)
])
# Add range slider
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=5,
label="last 5y",
step="year",
stepmode="backward"),
dict(count=10,
label="last 10y",
step="year",
stepmode="backward"),
dict(step="all")
]),
x=0.8,
y=1.21
),
rangeslider=dict(
visible=True
),
type="date"
)
)
# Set titles
fig.update_layout(
title="Top " + str(top_n) + " type of trees",
xaxis_title="Date of planting",
yaxis_title="Count of trees",
autosize=False,
width=1000,
height=700,
)
fig.update_layout(legend=dict(x=0, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='top6_tree_specie-date')
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['ANY_PLANTACIO']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['ANY_MES_PLANTACIO']!='NO_DATA']
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']!='NO_DATA']
df_arbrat_type_count = df_arbrat_interactive.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_type_count = df_arbrat_type_count.sort_values(['CODI'], ascending=False)
# Three df grouped by
df_arbrat_year = df_arbrat_interactive.groupby(['ANY_PLANTACIO','NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_year_month = df_arbrat_interactive.groupby(['ANY_MES_PLANTACIO','NOM_CIENTIFIC'], as_index=False).count()
# Initialize figure
fig = go.Figure()
top_n = 6
tree_types = list()
# Add Traces
for tree_type in df_arbrat_type_count['NOM_CIENTIFIC'].unique()[:top_n]:
tree_types.append(str(tree_type))
fig.add_trace(
go.Bar(x=df_arbrat_year[df_arbrat_year['NOM_CIENTIFIC']==tree_type]['ANY_PLANTACIO'],
y=df_arbrat_year[df_arbrat_year['NOM_CIENTIFIC']==tree_type]['CODI'],
name=tree_type))
fig.add_trace(
go.Bar(x=df_arbrat_year_month[df_arbrat_year_month['NOM_CIENTIFIC']==tree_type]['ANY_MES_PLANTACIO'],
y=df_arbrat_year_month[df_arbrat_year_month['NOM_CIENTIFIC']==tree_type]['CODI'],
visible=False,
name=tree_type))
# Add drowdowns
fig.update_layout(
updatemenus=[
dict(
buttons=list([
dict(label="All by Year",
method="update",
args=[{"visible": [True, False, True, False, True, False,
True, False, True, False, True, False,
True, False, True, False, True, False
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
dict(label="All by Year-Month",
method="update",
args=[{"visible": [False, True, False, True, False, True,
False, True, False, True, False, True,
False, True, False, True, False, True
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
]),
type="buttons",
direction="right",
active=0,
x=1.0,
y=1.15,
),
dict(
buttons=list([
dict(label="All by Year",
method="update",
args=[{"visible": [True, False, True, False, True, False,
True, False, True, False, True, False,
True, False, True, False, True, False
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
dict(label=str(tree_types[0]),
method="update",
args=[{"visible": [True] + 11*[False]},
{"title": "Type of tree:<br>" + str(tree_types[0]) + " by Year"}]),
dict(label=str(tree_types[1]),
method="update",
args=[{"visible": 2*[False] + [True] + 9*[False]},
{"title": "Type of tree:<br>" + str(tree_types[1]) + " by Year"}]),
dict(label=str(tree_types[2]),
method="update",
args=[{"visible": 4*[False] + [True] + 7*[False]},
{"title": "Type of tree:<br>" + str(tree_types[2]) + " by Year"}]),
dict(label=str(tree_types[3]),
method="update",
args=[{"visible": 6*[False] + [True] + 5*[False]},
{"title": "Type of tree:<br>" + str(tree_types[3]) + " by Year"}]),
dict(label=str(tree_types[4]),
method="update",
args=[{"visible": 8*[False] + [True] + 3*[False]},
{"title": "Type of tree:<br>" + str(tree_types[4]) + " by Year"}]),
dict(label=str(tree_types[5]),
method="update",
args=[{"visible": 10*[False] + [True] + [False]},
{"title": "Type of tree:<br>" + str(tree_types[5]) + " by Year"}]),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.38,
xanchor="left",
y=1.33,
yanchor="top"
),
dict(
buttons=list([
dict(label="All by Year-Month",
method="update",
args=[{"visible": [False, True, False, True, False, True,
False, True, False, True, False, True,
False, True, False, True, False, True
]},
{"title": "Top " + str(top_n) + " type of trees"}]),
dict(label=str(tree_types[0]),
method="update",
args=[{"visible": [False] + [True] + 10*[False]},
{"title": "Type of tree:<br>" + str(tree_types[0]) + " by Year-month"}]),
dict(label=str(tree_types[1]),
method="update",
args=[{"visible": 3*[False] + [True] + 8*[False]},
{"title": "Type of tree:<br>" + str(tree_types[1]) + " by Year-month"}]),
dict(label=str(tree_types[2]),
method="update",
args=[{"visible": 5*[False] + [True] + 6*[False]},
{"title": "Type of tree:<br>" + str(tree_types[2]) + " by Year-month"}]),
dict(label=str(tree_types[3]),
method="update",
args=[{"visible": 7*[False] + [True] + 4*[False]},
{"title": "Type of tree:<br>" + str(tree_types[3]) + " by Year-month"}]),
dict(label=str(tree_types[4]),
method="update",
args=[{"visible": 9*[False] + [True] + 2*[False]},
{"title": "Type of tree:<br>" + str(tree_types[4]) + " by Year-month"}]),
dict(label=str(tree_types[5]),
method="update",
args=[{"visible": 11*[False] + [True]},
{"title": "Type of tree:<br>" + str(tree_types[5]) + " by Year-month"}]),
]),
direction="down",
pad={"r": 10, "t": 10},
showactive=True,
x=0.38,
xanchor="left",
y=1.185,
yanchor="top"
),
]
)
fig.update_layout(
annotations=[
dict(text="Year", x=0.345, xref="paper", y=1.275, yref="paper",
align="left", showarrow=False),
dict(text="Year-Month", x=0.275, xref="paper", y=1.13, yref="paper",
showarrow=False)
])
# Add range slider
fig.update_layout(
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=5,
label="last 5y",
step="year",
stepmode="backward"),
dict(count=10,
label="last 10y",
step="year",
stepmode="backward"),
dict(step="all")
]),
x=0.8,
y=1.21
),
rangeslider=dict(
visible=True
),
type="date"
)
)
# Set titles
fig.update_layout(
title="Top " + str(top_n) + " type of trees",
xaxis_title="Date of planting",
yaxis_title="Count of trees",
autosize=False,
barmode='stack',
width=1000,
height=700,
)
fig.update_layout(legend=dict(x=0, y=1, bgcolor='rgba(255, 255, 255, 0)'))
fig.update_yaxes(automargin=True)
fig.show()
py.plot(fig, filename='top6_tree_specie-date-stacked')
lat_BCN = 41.408000
lon_BCN = 2.154007
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']!='NO_DATA']
df_arbrat_interactive_count = df_arbrat_interactive.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_interactive_count = df_arbrat_interactive_count.sort_values(['CODI'], ascending=False)
top_n = 6
# Initialize figure
fig = go.Figure()
tree_names = list()
# Add Traces
# fig.add_trace(
# go.Densitymapbox(lat=df_arbrat_interactive["LATITUD_WGS84"],
# lon=df_arbrat_interactive['LONGITUD_WGS84'],
# radius=4))
for tree_name in df_arbrat_interactive_count['NOM_CIENTIFIC'].unique()[:top_n]:
tree_names.append(str(tree_name))
fig.add_trace(
go.Densitymapbox(lat=df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']==tree_name]["LATITUD_WGS84"],
lon=df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']==tree_name]['LONGITUD_WGS84'],
radius=4))
# Add Buttons
fig.update_layout(
updatemenus=[
dict(
dict(
# active=0,
# type="buttons",
# direction="right",
active=0,
x=0.8,
y=0.99,
buttons=
list([
dict(label="All top 6 tree species",
method="update",
args=[{"visible": [True, True, True, True, True, True]},
{"title": "All top 6 tree species"}]),
dict(label=tree_names[0],
method="update",
args=[{"visible": [True, False, False, False, False, False]},
{"title": tree_names[0]}]),
dict(label=tree_names[1],
method="update",
args=[{"visible": [False, True, False, False, False, False]},
{"title": tree_names[1]}]),
dict(label=tree_names[2],
method="update",
args=[{"visible": [False, False, True, False, False, False]},
{"title": tree_names[2]}]),
dict(label=tree_names[3],
method="update",
args=[{"visible": [False, False, False, True, False, False]},
{"title": tree_names[3]}]),
dict(label=tree_names[4],
method="update",
args=[{"visible": [False, False, False, False, True, False]},
{"title": tree_names[4]}]),
dict(label=tree_names[5],
method="update",
args=[{"visible": [False, False, False, False, False, True]},
{"title": tree_names[5]}])
]),
)
)
])
fig.update_layout(mapbox_style="stamen-terrain",
mapbox_center_lon=lon_BCN,
mapbox_center_lat=lat_BCN,
mapbox_zoom=12
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
lat_BCN = 41.408000
lon_BCN = 2.154007
# Load dataset
df_arbrat_interactive = df_arbrat.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']!='NO_DATA']
df_arbrat_interactive_count = df_arbrat_interactive.groupby(['NOM_CIENTIFIC'], as_index=False).count()
df_arbrat_interactive_count = df_arbrat_interactive_count.sort_values(['CODI'], ascending=False)
top_n = 6
tree_names = list()
for tree_name in df_arbrat_interactive_count['NOM_CIENTIFIC'].unique()[:top_n]:
tree_names.append(str(tree_name))
# Initialize figure
f = plt.figure()
f, axes = plt.subplots(nrows = 3,
ncols = 2,
sharex=True,
sharey = True,
figsize=(10,10),
dpi=100)
# Add Traces
i=1
row_num=0
col_num=0
for tree_name in tree_names:
x=df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']==tree_name]['LONGITUD_WGS84']
y=df_arbrat_interactive[df_arbrat_interactive['NOM_CIENTIFIC']==tree_name]["LATITUD_WGS84"]
# Calculate the point density
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)
axes[row_num][col_num].scatter(x=x,
y=y,
c=z,
s=1,
marker = "o")
axes[row_num][col_num].set_xlabel(tree_name, labelpad = 5)
if i%2 == 0:
row_num += 1
col_num = 0
else:
col_num += 1
i+=1
plt.tight_layout()
plt.savefig('heatmap_subplots_tree_type.png')
plt.show()
lat_BCN = 41.408000
lon_BCN = 2.154007
# Load dataset
df_arbrat_interactive = df_gardens.copy(deep=True)
df_arbrat_interactive = df_arbrat_interactive[df_arbrat_interactive['LATITUD']!='NO_DATA']
# Initialize figure
fig = go.Figure()
# Add Traces
fig.add_trace(
go.Scattermapbox(lat=df_arbrat_interactive["LATITUD"],
lon=df_arbrat_interactive['LONGITUD'],
marker=go.scattermapbox.Marker(size=10, color='rgb(125, 255, 125)'),
text=df_arbrat_interactive['EQUIPAMENT']
))
fig.update_layout(mapbox_style="stamen-terrain",
mapbox_center_lon=lon_BCN,
mapbox_center_lat=lat_BCN,
mapbox_zoom=12
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
py.plot(fig, filename='gardens_and_parks-location')
This notebook has been done by Arnau Gatell, DTU student number 192334.